﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LunwenYun.Infrastructure.Entities.Entity;
using LunwenYun.Tool.Framework;

namespace LunwenYun.Infrastructure.Entities.Cache
{
    public class PeriodicalCache : EntitiesCache<Periodical>
    {
        /// <summary>
        /// key为 journalId
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public override Periodical GetItem(params string[] keys)
        {
            return base.GetItem(keys);
        }
        protected override bool ValidateParameter(params string[] keys)
        {
            return keys.Length == 1 && !String.IsNullOrEmpty(keys[0]);
        }
        protected override Periodical LoadDataItem(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                string journalId = keys[0];
                int id = journalId.ToInt32();
                var journal = new Periodical().Find(c => c.Id == id);
                return journal;
            }
            return null;
        }

        protected override string BuildKey(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                return String.Format("GetJournalEntity_{0}", keys[0]);
            }
            return string.Empty;
        }

        protected override string BuildKey(Periodical data)
        {
            if (data != null)
            {
                return BuildKey(data.Id.ToString());
            }
            return string.Empty;
        }
    }
}
